<?php
/**
 * @version			$Id$
 * @author			Richard Asp
 * @package			Joomla
 * @subpackage		gnudoor
 * @copyright		(C) 2010 gnudoor LLC
 * @license      GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * See COPYRIGHT.php for copyright notices and details.
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
jimport( 'joomla.application.component.model' );

class GnudoorModelProviders extends JModel
{
		function __construct() {
            parent::__construct();
            global $mainframe, $option;
            
            $active_tab = $mainframe->getUserStateFromRequest( $option.'active_tab', 'active_tab', 'tab_one', 'word' );
            $this->setState('active_tab', $active_tab);
            
        }

        function getRecord($cid = null) {
			$query = ' SELECT * '
				. ' FROM #__gnudoor '
				. ' WHERE id=' . $cid
			;
	        $this->_db->setQuery($query); 
	        $this->_data = $this->_db->loadObject(); 
        	return $this->_data;
        	
        }

        function getData() {
			$query = ' SELECT * '
				. ' FROM #__gnudoor '
		//		. ' WHERE status > 0 '
			;
	        $this->_db->setQuery($query); 
	        $this->_data = $this->_db->loadObjectList(); 
        	return $this->_data;
		}
        
        function getGnudoorGroup() {
			$query = ' SELECT userid, gnudoor_group '
				. ' FROM #__gnudoor_acl '
				;
			$this->_db->setQuery($query);
		    return $this->_db->loadObjectList();
			
		}

		function getUserName($uid = null) {
			$query = ' SELECT name '
				. ' FROM #__users '
				. ' WHERE id=' . $uid;
				;
		    $this->_db->setQuery($query);
		    return $this->_db->loadObject();
		    // return $provName;
		}

		function getAttributeArray() {
			$query = ' SELECT attribute, text '
				. ' FROM #__gnudoorproperties ';
		    $this->_db->setQuery($query);
		    $this->_attrib = $this->_db->loadObjectList();
		    foreach ($this->_attrib as $item) {
		    	$array[$item->attribute] = $item->text;
		    }
		    return $array;
		
		}

		function store() {
			$row =& $this->getTable('bids');
			$data = JRequest::get( 'post' );
			// Bind the form fields to the table
			if (!$row->bind($data)) {
				$this->setError($this->_db->getErrorMsg());
				return false;
			}
			// Make sure the Gnudoor record is valid
			if (!$row->check()) {
				$this->setError($this->_db->getErrorMsg());
				return false;
			}
			// Store the web link table to the database
			if (!$row->store()) {
				$this->setError( $this->_db->getErrorMsg() );
				return false;
			}
			return true;
		}

		function getArticleID($articlealias = null) {
			$query = ' SELECT id '
				. ' FROM #__content '
				. ' WHERE alias="' . $articlealias . '"'
				;
			$this->_db->setQuery($query);
		    return $this->_db->loadObject();	
		}
}
?>